﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TimbreRecognition.Recognition.Model
{
    public class NetworkClassifierWrapper : INetwork
    {
        private INetwork network;

        public NetworkClassifierWrapper(INetwork network)
        {
            this.network = network;
        }

        public double[] getOutput()
        {
            double[] output = network.getOutput();
            return classify(output);
        }

        public void recalculateOutput(double[] input)
        {
            network.recalculateOutput(input);
        }

        private double[] classify(double[] data)
        {
            double[] result = new double[data.Length];
            int index = getIndexOfMaxElement(data);
            result[index] = 1;

            return result;
        }

        private int getIndexOfMaxElement(double[] data)
        {
            double max = Double.MinValue;
            int index = 0;
            for (int i = 0; i < data.Length; i++)
            {
                double value = data[i];
                if (value > max)
                {
                    max = value;
                    index = i;
                }
            }

            return index;
        }
    }
}
